#include "stdafx.h"
#include "xContainer.h"
#include <vector>

#define ROOT ((std::vector<void*>*)m_hRoot)

xContainer::xContainer()
{
	m_hRoot = new std::vector<void*>;
}

xContainer::~xContainer()
{
	if(m_hRoot != NULL)
	{
		delete ROOT;
	}
}

void xContainer::Insert(void *pObject)
{
	if(ROOT != NULL)
	{
		ROOT->push_back(pObject);
	}
}
	
void xContainer::Remove(void *pObject)
{
	if(ROOT != NULL)
	{
		std::vector<void*>::iterator	itor = find(ROOT->begin(), ROOT->end(), pObject);

		if(itor != ROOT->end())
		{
			ROOT->erase(itor);
		}
	}
}

void xContainer::Clear()
{
	if(ROOT != NULL)
	{
		ROOT->clear();
	}
}

void *xContainer::GetAt(INT index)
{
	if(ROOT != NULL)
	{
		return ROOT->at(index);
	}
	return NULL;
}

UINT xContainer::GetCount()
{
	if(ROOT != NULL)
	{
		return ROOT->size();
	}
	return 0;
}

xContainer &xContainer::operator = (xContainer &container)
{
	*ROOT = *((std::vector<void*>*)container.m_hRoot);
	return *this;
}